package com.tank.collision;

import com.almasb.fxgl.dsl.components.EffectComponent;
import com.almasb.fxgl.dsl.components.HealthIntComponent;
import com.almasb.fxgl.entity.Entity;
import com.almasb.fxgl.physics.CollisionHandler;
import com.tank.constant.Config;
import com.tank.constant.GameType;
import com.tank.effect.HelmetEffect;
import com.tank.effect.ShipEffect;

public class BulletPlayerCollideHandler extends CollisionHandler {
    public BulletPlayerCollideHandler() {
        super(GameType.BULLET, GameType.PLAYER);
    }

    @Override
    protected void onCollisionBegin(Entity bullet, Entity player) {
        boolean hasHelmet = player.getComponent(EffectComponent.class).hasEffect(HelmetEffect.class);
        if (!hasHelmet) {
            if (player.getComponent(EffectComponent.class).hasEffect(ShipEffect.class)) {
                //remove ship effect
                player.getComponent(EffectComponent.class).endEffect(ShipEffect.class);
            } else {
                player.getComponent(HealthIntComponent.class).damage(bullet.getInt(Config.BULLET_LEVEL_KEY) + 1);
            }
        }
        bullet.removeFromWorld();
    }
}
